package com.fzdy.dataplatform.dao.impl;

import com.fzdy.dataplatform.core.dao.impl.BaseDaoImpl;
import org.hibernate.Query;
import org.hibernate.Session;

import java.io.Serializable;

public class PseudoDelete<T> extends BaseDaoImpl<T> {

    @Override
    public void batchDelete(Serializable[] ids) {
        if (ids==null||ids.length==0){
            return;
        }
        String hql = "";
        for (int i = 0; i < ids.length; i++) {
            if (i == 0) {
                hql = "id=" + ids[i];
            } else {
                hql = hql + " or id=" + ids[i];
            }
        }
        Session session = this.getSession();
        String s="update " + clazz.getName() + " set status = 0 where " + hql;
        Query q = session.createQuery(s);
        q.executeUpdate();
    }
}
